package com.gxa.modules.service.yxw.impl;
import com.gxa.common.vo.R2;
import com.gxa.modules.mapper.yxw.LogMapper;
import com.gxa.modules.service.yxw.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class LogServiceImpl implements LogService{
    R2 r  = new R2();
    @Autowired(required = false)
    private LogMapper logMapper;
Logger logger= LoggerFactory.getLogger(LogServiceImpl.class);
    public R2  selectlog(Map map) {
        int currentPage = Integer.parseInt((String) map.get("currentPage"));
        //每页显示条数
        int pageSize = Integer.parseInt((String) map.get("pageSize"));
        String username = (String) map.get("username");
        //当前页
        Integer newCurrentPage = (currentPage - 1) * pageSize;
//        Map map1 = new HashMap();
//        map1.put("username",username);
        map.put("page",newCurrentPage);
        map.put("limit",pageSize);

        try{
            List<Map> selectlog =  logMapper.selectlog(map);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(selectlog);
            //输出
            logger.info("查询成功");
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差了，请联系管理员");
        }
        return r;
    }



    @Override
    public R2 selectlogdate(Map map) {
        int currentPage = Integer.parseInt((String) map.get("currentPage"));
        int pageSize = Integer.parseInt((String) map.get("pageSize"));
        Integer newCurrentPage = (currentPage - 1) * pageSize;
        map.put("limit",newCurrentPage);
        map.put("page",pageSize);
        try {
            List<Map> selectlogdate = logMapper.selectlogdate(map);

            r.setCode(200);
            r.setData(selectlogdate);
            logger.info("查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差了，请联系管理员");
        }

        return r;
    }
}
